import redis
import  mqClientStat
import  sys
class task():
    def __init__(self,r,ip):
        self.ip = ip
        self.r = r

    def submitTask(self,command):
        self.r.lpush(self.ip+'list',command)
        p = self.r.pubsub()
        p.subscribe('queue')
        for item  in p.listen():
            try:
                print item
                data = eval(item['data'])
                print data[1]
                if data[1] == command:
                    break ;
            except Exception, exception:
                print exception




if __name__ == '__main__':
    pool = redis.ConnectionPool(host='localhost',port=6379, db=0)
    r = redis.StrictRedis(connection_pool=pool)
    stat  = mqClientStat.mqClientStat()
    lltask = task(r,stat.get_netcard()[0][1])
    lltask.submitTask(sys.argv[1])

